package com.ssm.reader.service.impl;

import com.ssm.reader.entity.User;
import com.ssm.reader.mapper.UserMapper;
import com.ssm.reader.service.UserService;
import com.ssm.reader.service.exception.BussinessException;
import com.ssm.reader.utils.MD5Utils;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;

/*
 *
 *
 *@data 2022-05-05
 */
@Service("userService")
@Transactional(propagation = Propagation.NOT_SUPPORTED,readOnly = true)
public class UserServiceImpl implements UserService {
    @Resource
    private UserMapper userMapper;

    public User checkLogin(String username, String password) {
        User user = userMapper.selectByUsername(username);

        if(user == null){
            //抛出异常
            throw new BussinessException("Loo1","用户名不存在");
        }
        String md5 = MD5Utils.md5Digest(password,user.getSalt());
        if(!md5.equals(user.getPassword())){
            throw new BussinessException("Loo2","密码错误");
        }
        return user;

    }
}
